<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.w3.org/1999/xhtml">
<html>
<head>
    <meta charset="utf-8">
    <title>基本资料</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="Layuimini/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="Layuimini/css/public.css" media="all">
    <link href="chongwu/collect.css" rel="stylesheet" type="text/css" />
    <style>
        .layui-form-item .layui-input-company {width: auto;padding-right: 10px;line-height: 38px;}
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <div class="layui-form layuimini-form">
            <div class="layui-row">
                <div class="layui-col-md7">
                    <input type="hidden" name="id"  th:value="${id}"  value="" class="layui-input">
                    <div class="layui-form-item">
                        <!-- <label class="layui-form-label required">账号名称</label>
                         <div class="layui-input-block">
                             <input type="text" name="username"   value="admin" th:value="${username}"  disabled readonly class="layui-input layui-disabled">
                         </div>-->
                        <label class="layui-form-label">当前账号</label>
                        <div class="layui-card-header" th:text="${username}"></div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label required">手机</label>
                        <div class="layui-input-block">
                            <input type="number" name="mobile"    th:value="${mobile}" lay-verify="required" lay-reqtext="手机不能为空" placeholder="请输入手机"  value="" class="layui-input">
                        </div>
                    </div>


                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button type="button" class="layui-btn xs" name="avatar" id="avatar">
                                <i class="layui-icon">&#xe67c;</i>设置头像图片
                            </button>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">头像介绍</label>
                        <div class="layui-input-block">
                            <input type="text" name="letter"  th:value="${letter}" placeholder="头像介绍"  value="" class="layui-input">
                        </div>
                    </div>


                    <div class="layui-form-item">
                        <label class="layui-form-label">邮箱</label>
                        <div class="layui-input-block">
                            <input type="email" name="email"  th:value="${email}" placeholder="请输入邮箱"  value="" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">备注信息</label>
                        <div class="layui-input-block">
                            <textarea name="remark" th:text="${remark}" class="layui-textarea" placeholder="请输入备注信息"></textarea>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn layui-btn-primary layui-border-green" lay-submit lay-filter="saveBtn">确认保存</button>

                            <button type="button" class="layui-btn layui-btn-primary layui-border-orange" id="resetBtn">重置</button>
                        </div>
                    </div>
                </div>
                <div class="layui-col-md5">

                    <div class="flip-wrapper" style="width: 250px;height: 250px;margin-left: 30px;margin-top: 20px" onclick="changeClass(this)">
                        <div class="flip-a">
                            <img class="coverd" style="width: 275px; height: 275px;" th:src="${avatar}" alt="图片加载失败">
                        </div>
                        <div class="flip-b">
                            <h1> [[${letter}]]</h1>
                        </div>
                    </div>
                </div>
            </div>
        </div>



    </div>
</div>
<script src="Layuimini/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="Layuimini/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>


    var isUp = true
    function changeClass(el) {
        if (isUp) {
            el.className = 'flip-wrapper is-flipped';
        } else {
            el.className = 'flip-wrapper';
        }
        isUp = !isUp
    }



    layui.use(['form','miniTab','upload'], function () {
        var form = layui.form,
            layer = layui.layer,
            miniTab = layui.miniTab,
            upload = layui.upload,
            $ = layui.$;

        var avatar ;
        //执行实例
        var uploadInst = upload.render({
            elem: '#avatar' //绑定元素
            ,url: 'tx/avatar/upload' //上传接口
            ,field: 'avatar'
            ,done: function(res){
                //上传完毕回调
                //console.log(res.data.url);
                avatar= res.data.url;

              layer.alert("图片上传成功,确认保存后可预览!")
            }
            ,error: function(){
                //请求异常回调
            }
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            data.field.avatar = avatar;
            //console.log(data.field.avatar);
            //console.log(data.field);
            var id = data.field.id;
            this.disabled=true;//防止按钮重复提交
        /*    var index = layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'
            }, function () {
                layer.close(index);
                miniTab.deleteCurrentByIframe();
            });*/

            //保存操作
            $.ajax({
                url:"superLoginUser/getUserInfoById/"+id,
                type:"POST",
                data:data.field,
                contentType: 'application/json; charset=UTF-8',
                async:false,
                dataType:'json',
                data:JSON.stringify(data.field),
                success:function(result){
                    layer.msg('用户信息保存成功！',{
                        icon:6,
                        time:2000
                    },function(){
                       // window.parent.location.reload();  //刷新父页面
                        //window.location.reload();
                        miniTab.deleteCurrentByIframe();
                    })

                }
            });

            return false;
        });

        $("#resetBtn").click(function () {
            layer.msg("重置成功！", {
                time: 1000, //6s后自动关闭
                icon:6,
            },function () {
                window.location.reload();
                }
            );
        })

    });
</script>
</body>
</html>